﻿using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace StudentsPrenseLog.Models
{
    public class Student
    {
        public Guid Id           { get; protected set; }
        public String FirstName  { get; protected set; }
        public String LastName   { get; protected set; }
        public DateTime Birthday { get; protected set; }
        public float AverageMark { get; protected set; }
        public bool HasStependy  { get; protected set; }

        public Student(String lastName,String firstName,DateTime birthDate,float averageMark)
        {
            this.Id          = Guid.NewGuid();
            this.FirstName   = firstName;
            this.LastName    = lastName;
            this.Birthday    = birthDate;
            this.AverageMark = averageMark;
        }

        public void Rename(String newFirstName, String newLastName)
        {
            this.FirstName = newFirstName;
            this.LastName  = newLastName;
        }

        public Student(String serializedString, String delimeter, String dateFormat)
        {
            String[] chunks = serializedString.Split(delimeter[0]);

            this.Id          = Guid.Parse(chunks[0]);
            this.FirstName   = chunks[1];
            this.LastName    = chunks[2];
            this.Birthday    = DateTime.ParseExact(chunks[3], dateFormat, CultureInfo.InvariantCulture);
            this.AverageMark = Single.Parse(chunks[4]);
        }

        public String SerializeToString(String delimeter,String dateFormat)
        {
            return String.Format("{0}{1}{2}{3}{4}{5}{6}{7}{8}",
                this.Id.ToString(), delimeter, this.FirstName, delimeter,
                this.LastName, delimeter, this.Birthday.ToString(dateFormat), delimeter,
                this.AverageMark.ToString());
        }

        public bool FitSearchPattern(String searchPattern)
        {
            return true;
        }

        public override string ToString()
        {
            return SerializeToString(";", CultureInfo.InvariantCulture.DateTimeFormat.ShortDatePattern);
        }

        public byte[] SerializeToBinary()
        {
            throw new NotImplementedException();
        }

    }
}
